<?php
namespace app\controller;

use think\Request;
use think\facade\Db;

class Main extends Common
{
	/**
	* 修改密码
	*
	* @return
	*/
	function password(Request $request) {
		$old = $request->param('old', '', 'trim');
		if(empty($old)) {
			return ['code'=>403, 'msg'=>'原密码不能为空, 修改失败!'];
		}
		$new = $request->param('password', '', 'trim');
		if(empty($new)) {
			return ['code'=>403, 'msg'=>'新密码不能为空, 修改失败!'];
		}
		$password = Db::table('cfg_user')->where('id', $request->sessInfo['id'])->value('password');
		if (!password_verify($old, $password)) {
			return json(['code'=>403, 'msg' => '原密码错误, 修改失败!']);
		}
		$password = password_hash($new, PASSWORD_BCRYPT, ['cost' => 10]);
		Db::name('cfg_user')->where('id', $request->sessInfo['id'])->update(['password' => $password]);
		return ['code'=>0, 'msg'=>'密码修改成功!'];
	}
}